<template>
  <div class="bg">
    <div class="login">
      <header>VUE-ADMIN 后台管理系统</header>
      <el-form :model="user" :rules="rules" ref="loginForm">
        <el-form-item prop="username">
          <el-input placeholder="请输入帐号" v-model="user.username">
            <i slot="prefix" class="el-icon-user" style="font-size: 18px;"></i>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" placeholder="请输入密码" v-model="user.password">
            <i slot="prefix" class="el-icon-key" style="font-size: 18px;"></i>
            <i slot="suffix" class="el-icon-view" style="cursor: pointer;"></i>
          </el-input>
        </el-form-item>
        <el-form-item prop="yanZhengCode" class="yanZhengCode">
          <el-input type="text" placeholder="请输入验证码">
            <i slot="prefix" class="el-icon-attract" style="font-size: 18px;"></i>
          </el-input>
          <!-- <validate-code ref="validate-code"></validate-code> -->
        </el-form-item>
        <el-form-item>
          <el-button
            type="success"
            :loading="loading"
            @click="doLogin"
          >{{loading ? "登陆中..." : "登录系统"}}</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      loading: false,
      user: {
        username: "",
        password: "",
        yanZhengCode: ""
      },
      //校验规则
      rules: {
        username: [{ required: true, message: "请输入帐号", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  mounted() {},
  methods: {
    doLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          //成功
          this.$message.success("登陆成功");
          //存储用户登陆成功的信息
          let obj = {
            //随机生成token值
            token: "123456789",
            username: this.username
          };
          this.$store.commit("doLogin", obj);
          //调转到主页面
          this.$router.push("/homework/home");
        }
      });
    }
  },
  computed: {},
  watch: {}
};
</script>

<style lang="scss" scoped>
.bg {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgb(32, 160, 255);
  .login {
    header {
      width: 100%;
      font-size: 28px;
      color: #fff;
      line-height: 50px;
      text-align: center;
      font-weight: bold;
      position: absolute;
      top: 25%;
      left: 50%;
      transform: translate(-50%, -60%);
    }
    .el-form {
      width: 70%;
      background-color: #fff;
      position: absolute;
      top: 55%;
      left: 50%;
      transform: translate(-50%, -60%);
      padding: 20px;
      box-sizing: border-box;
      border: 1px solid #fff;
      border-radius: 6px;
      .yanZhengCode {
        width: 40%;
      }
    }
    .el-button {
      width: 100%;
    }
  }
}
</style>